﻿using System;
using System.Collections.Generic;
using ProtoBuf;
using ProtoBuf.Meta;

namespace mst_regex
{
    public class StockPositions : StockPositionsBase<StockPosition>
    {
        private Dictionary<string, StockPosition> DictShim
        {
            get
            {
                var model = TypeModel.Create();
                return (Dictionary<string, T>)model.DeepClone(_listRecords);
            }

            set
            {

            }
        }

        public StockPositions() : this(StockExchangeType.Dse, DateTime.Today)
        {
        }

        public StockPositions(StockExchangeType exchange, DateTime date) : base(exchange, date)
        {
        }

        public void AddRecord(string symbol, decimal open, decimal close, decimal high, decimal low, decimal change,
                              decimal value, int trades, int volume)
        {
            var record = new StockPosition
                             {
                                 Symbol = symbol.Trim().ToUpper(),
                                 Open = open,
                                 High = high,
                                 Low = low,
                                 Close = close,
                                 Change = change,
                                 Trades = trades,
                                 Volume = volume,
                                 ValueInMillions = value,
                                 EffectiveDate = EffectiveDate,
                                 StockExchange = StockExchange
                             };
            AddItem(symbol, record);
        }

        public string ToXml()
        {
            return ToXml<StockPosition>();
        }
    }
}